﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
public partial class danye : AdminpageBase
{
    protected string strtitle = ReadRequest.RequestString("title");
    protected Model.CompanyIntr model = null;
    protected int id = ReadRequest.RequestInt("id");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            inidata();
        }
    }
    private void inidata()
    {
        model = BLL.CompanyIntr.GetModel(id);
        if (model != null)
        {
            texteid.Text = id.ToString();
            txtContent.Value = model.Content;
        }
    }

    //提交按钮事件
    protected void btn_submit_Click(object sender, EventArgs e)
    {
        Model.CompanyIntr m = BLL.CompanyIntr.GetModel(int.Parse(texteid.Text));
        if (m != null)
        {
            m.Details = strtitle;
            if (int.Parse(texteid.Text) == 16 || int.Parse(texteid.Text) == 17)
            {
                string value = txtContent.Value.Replace("<br />", "").Trim();
                //if (string.IsNullOrEmpty(value))
                //{
                //    Response.Write("<script type=\"text/javascript\">alert('金币或积分只能为正整数！');</script>");
                //    return;
                //}

                Regex reg = new Regex(@"^[0-9]+[0-9]*[.]?[0-9]*$");
                Match ma = reg.Match(value);
                if (ma.Success)
                {
                    m.Content = txtContent.Value;
                }
                else
                {
                    Response.Write("<script type=\"text/javascript\">alert('金币或积分只能为正整数！');</script>");
                    return;
                }

            }
            else
            {
                m.Content = txtContent.Value;
            }
            m.Content = txtContent.Value;
            m.UpTime = DateTime.Now;
            if (BLL.CompanyIntr.Update(m) > 0)
            {
                Response.Write("<script type=\"text/javascript\">alert('保存成功！');window.location.href = '/manage/danye.aspx?id='" + id + ";</script>");
                return;
            }
        }
    }
    protected bool isNumberic(string message, out int result)
    {
        //判断是否为整数字符串
        //是的话则将其转换为数字并将其设为out类型的输出值、返回true, 否则为false
        result = -1;   //result 定义为out 用来输出值
        try
        {
            //当数字字符串的为是少于4时，以下三种都可以转换，任选一种
            //如果位数超过4的话，请选用Convert.ToInt32() 和int.Parse()

            //result = int.Parse(message);
            //result = Convert.ToInt16(message);
            result = Convert.ToInt32(message);
            return true;
        }
        catch
        {
            return false;
        }
    }


}